package tmt.usercenter.web.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.tmt.annotation.Select2OptionItem;
import com.tmt.annotation.Select2OptionValue;
import com.tmt.jpafieldvalueconvert.JpaFieldValueConvert;
import com.tmt.jpafieldvalueconvert.impl.FileUrlFieldConverter;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import lombok.Getter;
import lombok.Setter;
import tmt.usercenter.web.domain.enums.IdCardType;
import tmt.usercenter.web.domain.enums.TmtUserType;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Date;

@Getter
@Setter
@MappedSuperclass
@JsonIdentityInfo(generator = JSOGGenerator.class)
public class UserInfo extends BaseDomain implements Serializable {

    /**
     * 用户头像, 提供默认头像
     */
    @Column(nullable = false)
    @JpaFieldValueConvert(converter = FileUrlFieldConverter.class, displayName = "用户头像")
    private String avatar = "";

    /**
     * 用户名
     */
    @Select2OptionItem
    @Column(nullable = false, unique = true)
    private String username;

    /**
     * 密码
     */
    @Column(nullable = false)
    private String password = "123456";

    /**
     * 用户昵称
     */
    @Select2OptionItem(order = 1)
    private String nickname;

    /**
     * 真实姓名
     */
    @Column
    private String realName;

    /**
     * 身份证号码
     */
    @Column
    private String idCardNum;

    /**
     * 证件类型
     */
    @Select2OptionValue("cardType")
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private IdCardType cardType = IdCardType.ID_CARD_2;

    /**
     * 用户生日
     */
    @Column
    private Date birthday;

    /**
     * 电话号码
     */
    @Column
    private String mobile;

    /**
     * 绑定邮箱，绑定后可用邮箱登录, 且可以找回密码
     */
    @Column
    private String email;

    /**
     * 会员星级
     */
    @Column(nullable = false)
    private int starLevel = 0;

    /**
     * 邮箱是否激活
     */
    @Column(nullable = false, columnDefinition = "TINYINT(1)")
    private boolean emailEnabled = false;

    /**
     * 电话号码是否激活
     */
    @Column(nullable = false, columnDefinition = "TINYINT(1)")
    private boolean mobileEnabled = false;

    @Column(nullable = false, columnDefinition = "TINYINT(1)")
    private boolean enabled = true;

    @Column(nullable = false, columnDefinition = "TINYINT(1)")
    private boolean online = false;

    @Column(nullable = false, columnDefinition = "TINYINT(1)")
    private boolean realNameChecked = false;

    @Column
    private int loginCount;

    @Select2OptionValue("userType")
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private TmtUserType userType = TmtUserType.USER;

    /**
     * 推荐人外部编号
     */
    @Column
    private Long introducerCode;

    /**
     * 外部系统编号
     */
    @Column(unique = true)
    private Long externalCode;

}